package com.zsj.juc.Atomic;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zsj
 * @version 1.0
 * @date 2024/5/17 12:16
 * @description
 */

@Getter
@ToString
@AllArgsConstructor
class T {
    String name;
    int age;
}

public class AtomicReferenceDemo {

    public static void main(String[] args) {
        AtomicReference<T> atomicReference = new AtomicReference<>();

        T t1 = new T("z", 1);
        T t2 = new T("s", 2);
        atomicReference.set(t1);
        System.out.println(atomicReference.compareAndSet(t1, t2));

        /*
        AtomicMarkableReference 和 AtomicStampedReference 的区别
        其实本质都是用来看数据是否被动过了
        AtomicMarkableReference 只能看到数据是否被动过 不能看到动了几次
        AtomicStampedReference 因为有戳记 可以看到被动了多少次
         */
    }
}
